package com.marion.mzuul.controller;

import com.marion.mzuul.service.UserLocationService;
import com.marion.mzuul.vo.NearbyUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/gps")
public class GpsController {

    @Autowired
    private UserLocationService userLocationService;

    /**
     * 定位上传 t_user
     */
    @RequestMapping(value = "/upload", method = {RequestMethod.GET, RequestMethod.POST})
    public Boolean upload(@RequestParam long uid,
                          @RequestParam int gender,
                          @RequestParam String address,
                          @RequestParam double lon,
                          @RequestParam double lat) {
        userLocationService.gps(uid, gender, address, lon, lat);
        return true;
    }

    /**
     * 查询附近的人
     */
    @RequestMapping(value = "/nearby", method = {RequestMethod.GET, RequestMethod.POST})
    public List<NearbyUser> nearby(@RequestParam long uid,
                                   @RequestParam(defaultValue = "5000000", required = false) long distance,
                                   @RequestParam(defaultValue = "0", required = false) int start,
                                   @RequestParam(defaultValue = "100", required = false) int count) {
        return userLocationService.nearby(uid, distance, start, count);
    }

}
